package com.sgcc.fj.pmos.mobileapp.fragment;

import android.app.Activity;
import android.content.Intent;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.blankj.utilcode.util.KeyboardUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.luck.picture.lib.basic.PictureSelector;
import com.luck.picture.lib.entity.LocalMedia;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.interfaces.OnSelectListener;
import com.sgcc.fj.pmos.common.base.MvpBaseFragment;
import com.sgcc.fj.pmos.common.bean.ImageInfoBean;
import com.sgcc.fj.pmos.common.http.HttpInterConst;
import com.sgcc.fj.pmos.common.utils.DateUtils;
import com.sgcc.fj.pmos.common.utils.DialogUtil;
import com.sgcc.fj.pmos.common.utils.GlideUtil;
import com.sgcc.fj.pmos.common.utils.XXPermissionsUtil;
import com.sgcc.fj.pmos.common.utils.picture.PictureSelectUtil;
import com.sgcc.pmos.nativesdk.R;
import com.sgcc.fj.pmos.mobileapp.activity.AssociatedEnterpriseInfoActivity;
import com.sgcc.fj.pmos.mobileapp.bean.DataDifferentItemBean;
import com.sgcc.fj.pmos.mobileapp.bean.QueryBusinessInfoBean;
import com.sgcc.fj.pmos.mobileapp.contract.BusinessInfoContract;
import com.sgcc.fj.pmos.mobileapp.presenter.BusinessInfoPresenter;
import com.sgcc.fj.pmos.mobileapp.utils.DataDifferentDialog;
import com.sgcc.fj.pmos.mobileapp.utils.OnNextListener;
import com.sgcc.fj.pmos.mobileapp.utils.TransInformation;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @author ChaoAJ
 * @describe 关联企业信息--工商信息
 * @time 2022/10/18 11:45
 */
public class BusinessInfoFragment extends MvpBaseFragment<BusinessInfoPresenter> implements BusinessInfoContract.View, View.OnClickListener {


    private String[] entTypes = new String[]{"有限责任公司",
            "股份有限公司", "有限责任公司分公司", "股份有限公司分公司", "事业单位营业"};

    private LinearLayout llInfoLayout;
    private TextView tvUnlockEdit;//解锁编辑
    private boolean isLock = true;//是否锁定
    private ImageView imgSelectImg;
    private EditText etTyshxydm;//必填 统一社会信用代码
    private TextView etZzjgdm;//组织机构代码
    private TextView etSwdjh;//税务登记号
    private EditText etName;//必填 名称
    private EditText etJc;//必填 简称
    private TextView tvEntType;//必填 企业类型
    private EditText etEntAddress;//必填 经营场所（住所）
    private EditText etCapital;//必填 注册资本（万元）
    private TextView tvEstablishTime;// 必填  成立时间
    private TextView tvStartTime;//营业期限（选填）开始时间
    private TextView tvEndTime;//营业期限（选填）结束时间
    private EditText etJyfw;//必填 经营范围
    private ImageView imgForever; //营业期限（选填）永久

    private boolean isForever = false;

    private String entType = "-1";//企业类型
    private String establishTime;//成立时间

    private String path;//营业执照地址

    private LinearLayout llImgBtnLayout;
    private TextView tvSee;//查看
    private TextView tvReUpload;//重新上传
    private TextView tvDelete;//删除


    //接口返回的营业执照信息
    private String creditcode;//统一社会信用代码
    private String membersName;//名称
    private String enterpriseType = "0";//企业类型
    private String regAddress;//经营场所（住所）
    private String regcapital;//注册资本（万元）
    private String founddate;//成立时间
    private String term;//营业期限
    private String scope;//经营范围
    private String legalReprName;//法人姓名

    private boolean isQueryBusinessInfoBack = false;


    private OnNextListener onNextListener;


    public static BusinessInfoFragment newInstance() {
        BusinessInfoFragment fragment = new BusinessInfoFragment();
        return fragment;
    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.fragment_business_info;
    }


    @Override
    protected BusinessInfoPresenter createPresenter() {
        return new BusinessInfoPresenter();
    }

    @Override
    protected void initViews() {
        super.initViews();
        tvUnlockEdit = mRootView.findViewById(R.id.tvUnlockEdit);
        llInfoLayout = mRootView.findViewById(R.id.llInfoLayout);
        imgSelectImg = mRootView.findViewById(R.id.imgSelectImg);


        llImgBtnLayout = mRootView.findViewById(R.id.llImgBtnLayout);
        tvSee = mRootView.findViewById(R.id.tvSee);
        tvReUpload = mRootView.findViewById(R.id.tvReUpload);
        tvDelete = mRootView.findViewById(R.id.tvDelete);


        etTyshxydm = mRootView.findViewById(R.id.etTyshxydm);
        etZzjgdm = mRootView.findViewById(R.id.tvZzjgdm);
        etSwdjh = mRootView.findViewById(R.id.tvSwdjh);
        etName = mRootView.findViewById(R.id.etName);
        etJc = mRootView.findViewById(R.id.etJc);
        tvEntType = mRootView.findViewById(R.id.tvEntType);
        etEntAddress = mRootView.findViewById(R.id.etEntAddress);
        etCapital = mRootView.findViewById(R.id.etCapital);
        tvEstablishTime = mRootView.findViewById(R.id.tvEstablishTime);
        tvStartTime = mRootView.findViewById(R.id.tvStartTime);
        tvEndTime = mRootView.findViewById(R.id.tvEndTime);
        etJyfw = mRootView.findViewById(R.id.etJyfw);
        imgForever = mRootView.findViewById(R.id.imgForever);


        tvSee.setOnClickListener(this);
        tvReUpload.setOnClickListener(this);
        tvDelete.setOnClickListener(this);
        tvUnlockEdit.setOnClickListener(this);
        imgSelectImg.setOnClickListener(this);
        tvEntType.setOnClickListener(this);
        tvEstablishTime.setOnClickListener(this);
        tvStartTime.setOnClickListener(this);
        tvEndTime.setOnClickListener(this);
        etTyshxydm.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                String creditcode = etTyshxydm.getText().toString().trim().toUpperCase();
                if (creditcode.length() == 18) {
                    StringBuilder stringBuilder = new StringBuilder(creditcode.substring(8, 17));
                    stringBuilder.insert(8, "-");
                    etZzjgdm.setText(stringBuilder.toString());
                    etSwdjh.setText(creditcode.substring(2, 17));
                }
            }
        });

        etTyshxydm.setTransformationMethod(new TransInformation());

        imgForever.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                isForever = !isForever;
                if (isForever) {
                    tvEndTime.setText("");
                }
                imgForever.setSelected(isForever);
                tvEndTime.setEnabled(!isForever);
                tvEndTime.setSelected(!isForever);
            }
        });
        mPresenter.queryBusinessInfo();
    }

    //更改锁定状态
    private void unlockEdit() {
        tvUnlockEdit.setText(isLock ? "解锁编辑" : "锁定");
        //统一社会信用代码
        etTyshxydm.setSelected(!isLock);
        etTyshxydm.setEnabled(!isLock);

        //名称
        etName.setSelected(!isLock);
        etName.setEnabled(!isLock);

        //企业类型
        tvEntType.setSelected(!isLock);
        tvEntType.setEnabled(!isLock);

        // 经营场所（住所）
        etEntAddress.setSelected(!isLock);
        etEntAddress.setEnabled(!isLock);

        //注册资本（万元）
        etCapital.setSelected(!isLock);
        etCapital.setEnabled(!isLock);

        //成立时间
        tvEstablishTime.setSelected(!isLock);
        tvEstablishTime.setEnabled(!isLock);

        //营业期限（选填）开始时间
        tvStartTime.setSelected(!isLock);
        tvStartTime.setEnabled(!isLock);

        //营业期限（选填）结束时间
        tvEndTime.setSelected(!isLock && !isForever);
        tvEndTime.setEnabled(!isLock && !isForever);
        //经营范围
        etJyfw.setSelected(!isLock);
        etJyfw.setEnabled(!isLock);

        //永久
        imgForever.setEnabled(!isLock);

    }


    @Override
    public void onClick(View view) {
        int id = view.getId();
        KeyboardUtils.hideSoftInput(getActivity());
        if (id == R.id.tvUnlockEdit) {
            isLock = !isLock;
            unlockEdit();
        } else if (id == R.id.imgSelectImg) {
            if (TextUtils.isEmpty(path)) {
                XXPermissionsUtil.camera(getActivity(), new XXPermissionsUtil.PermissionCallback() {
                    @Override
                    public void Call() {
                        PictureSelectUtil.select(BusinessInfoFragment.this, 0x21, true, null);
                    }
                });
            } else {
                DialogUtil.showImageDialog(getContext(), imgSelectImg, path);
            }
        } else if (id == R.id.tvReUpload) {
            XXPermissionsUtil.camera(getActivity(), new XXPermissionsUtil.PermissionCallback() {
                @Override
                public void Call() {
                    PictureSelectUtil.select(BusinessInfoFragment.this, 0x21, true, null);
                }
            });
        } else if (id == R.id.tvEntType) {
            new XPopup.Builder(getContext())
//                        .isViewMode(true)
                    .asBottomList("请选择一项", entTypes,
                            new OnSelectListener() {
                                @Override
                                public void onSelect(int position, String text) {
                                    entType = position + 1 + "";
                                    tvEntType.setText(text);


                                }
                            }).show();
        } else if (id == R.id.tvEstablishTime) {
            showDateSelect(1);
        } else if (id == R.id.tvStartTime) {
            showDateSelect(2);
        } else if (id == R.id.tvEndTime) {
            showDateSelect(3);
        } else if (id == R.id.tvSee) {
            DialogUtil.showImageDialog(getContext(), imgSelectImg, path);
        } else if (id == R.id.tvDelete) {
            llInfoLayout.setVisibility(View.GONE);
            tvUnlockEdit.setVisibility(View.GONE);
            imgSelectImg.setImageResource(R.mipmap.ic_select_img_bg);
            path = "";
            llImgBtnLayout.setVisibility(View.GONE);
        }
//        switch (id) {
//            case R.id.tvUnlockEdit:
//                isLock = !isLock;
//                unlockEdit();
//
//                break;
//            case R.id.imgSelectImg:
//                if (TextUtils.isEmpty(path)) {
//                    XXPermissionsUtil.camera(getActivity(), new XXPermissionsUtil.PermissionCallback() {
//                        @Override
//                        public void Call() {
//                            PictureSelectUtil.select(BusinessInfoFragment.this, 0x21, true, null);
//                        }
//                    });
//                } else {
//                    DialogUtil.showImageDialog(getContext(), imgSelectImg, path);
//                }
//                break;

//            case R.id.tvReUpload:
//
//                XXPermissionsUtil.camera(getActivity(), new XXPermissionsUtil.PermissionCallback() {
//                    @Override
//                    public void Call() {
//                        PictureSelectUtil.select(BusinessInfoFragment.this, 0x21, true, null);
//                    }
//                });
//
//                break;

//            case R.id.tvEntType:
//                new XPopup.Builder(getContext())
////                        .isViewMode(true)
//                        .asBottomList("请选择一项", entTypes,
//                                new OnSelectListener() {
//                                    @Override
//                                    public void onSelect(int position, String text) {
//                                        entType = position + 1 + "";
//                                        tvEntType.setText(text);
//
//
//                                    }
//                                }).show();
//
//
//                break;
//            case R.id.tvEstablishTime:
//                showDateSelect(1);
//                break;
//            case R.id.tvStartTime:
//                showDateSelect(2);
//                break;
//            case R.id.tvEndTime:
//                showDateSelect(3);
//                break;
//            case R.id.tvSee:
//                DialogUtil.showImageDialog(getContext(), imgSelectImg, path);
//                break;
//            case R.id.tvDelete:
//                llInfoLayout.setVisibility(View.GONE);
//                tvUnlockEdit.setVisibility(View.GONE);
//                imgSelectImg.setImageResource(R.mipmap.ic_select_img_bg);
//                path = "";
//                llImgBtnLayout.setVisibility(View.GONE);
//
//                break;
//
//        }
    }


    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == Activity.RESULT_OK) {
            if (requestCode == 0x21) {
                ArrayList<LocalMedia> localMediaList = PictureSelector.obtainSelectorList(data);
                if (null != localMediaList && localMediaList.size() > 0) {
                    path = PictureSelectUtil.getPath(localMediaList.get(0));
                    GlideUtil.loadImg(path, imgSelectImg);
                    mPresenter.uploadFile(path);
                }
            }
        }


    }


    @Override
    public void uploadFileSuccess(ImageInfoBean.Info info) {
        if (null != info) {
            showLayout();
            isQueryBusinessInfoBack = false;
            creditcode = info.getCreditcode().toUpperCase();//统一社会信用代码
            membersName = info.getMembersName();//名称
            enterpriseType = info.getEnterpriseType();//企业类型
            regAddress = info.getRegAddress();//经营场所（住所）
            regcapital = info.getRegcapital();//注册资本（万元）
            founddate = info.getFounddate();//成立时间
            String text = info.getTerm();
            if (text.contains("*")) {
                text = text.replace("*", "") + "永久";
            }
            term = text.replace("自", "").
                    replace("年", "-").replace("月", "-")
                    .replace("日", "").replace("*", "");//营业期限
            scope = info.getScope();//经营范围
            legalReprName = info.getLegalReprName();//法人姓名
            setText(0);
        }
    }


    @Override
    public void queryBusinessInfoSuccess(QueryBusinessInfoBean.BusinessInfo businessInfo) {
        if (null != businessInfo) {
            showLayout();
            isQueryBusinessInfoBack = true;
            List<QueryBusinessInfoBean.BusinessInfo.MmMembersAffixRegsDTO> mMembersAffixRegs =
                    businessInfo.getMmMembersAffixRegs();
            if (null != mMembersAffixRegs && mMembersAffixRegs.size() > 0) {
                QueryBusinessInfoBean.BusinessInfo.MmMembersAffixRegsDTO mmMembersAffixRegsDTO =
                        mMembersAffixRegs.get(0);
                path = HttpInterConst.BASEURL_IMG + mmMembersAffixRegsDTO.getFileId();
                GlideUtil.loadImg(path, imgSelectImg);
            }

            creditcode = businessInfo.getCreditcode().toUpperCase();//统一社会信用代码
            membersName = businessInfo.getMembersName();//名称
            enterpriseType = businessInfo.getEnterpriseType();//企业类型
            regAddress = businessInfo.getRegAddress();//经营场所（住所）
            regcapital = businessInfo.getRegcapital();//注册资本（万元）
            founddate = businessInfo.getFounddate();//成立时间

            term = businessInfo.getTerm().replace("自", "").
                    replace("年", "-").replace("月", "-")
                    .replace("日", "");//营业期限

            scope = businessInfo.getScope();//经营范围
            legalReprName = businessInfo.getLegalReprName();//法人姓名
            setText(1);


        }


    }

    @Override
    public void saveDataSuccess(String s) {
        if (null != onNextListener)
            onNextListener.onNext(true);
    }

    @Override
    public void onFailed(int code) {
        if (code == 0) {
            ToastUtils.showShort("文件上传失败");
        }
        if (code == 1) {
            showLayout();
            etTyshxydm.setText("");
            etZzjgdm.setText("");
            etSwdjh.setText("");
            etName.setText("");
            etJc.setText("");
            tvEntType.setText("");
            etEntAddress.setText("");
            etCapital.setText("");
            tvEstablishTime.setText("");
            imgForever.setSelected(false);
            etJyfw.setText("");
            tvStartTime.setText("");
            tvEndTime.setText("");
        }


    }


    /**
     * @param type 识别图片返回 enterpriseType是汉字
     *             查询结果返回是 数字
     */
    private void setText(int type) {

        ((AssociatedEnterpriseInfoActivity) getActivity()).setLegalReprName(legalReprName);

        etTyshxydm.setText(creditcode);
        if (creditcode.length() == 18) {

            StringBuilder stringBuilder = new StringBuilder(creditcode.substring(8, 17));
            stringBuilder.insert(8, "-");
            etZzjgdm.setText(stringBuilder.toString());
            etSwdjh.setText(creditcode.substring(2, 17));
        }
        etName.setText(membersName);
        etJc.setText(membersName);
        if (type == 0) {
            for (int i = 0; i < entTypes.length; i++) {
                if (enterpriseType.equals(entTypes[i])) {
                    entType = i + 1 + "";
                }
            }
        } else {
            entType = enterpriseType;
            try {
                enterpriseType = entTypes[Integer.parseInt(entType) - 1];
            } catch (Exception e) {
                entType = "-1";
                enterpriseType = "";
            }

        }
        ((AssociatedEnterpriseInfoActivity) getActivity()).setRegAddress(regAddress);
        tvEntType.setText(enterpriseType);
        etEntAddress.setText(regAddress);
        etCapital.setText(regcapital);
        establishTime = founddate;
        tvEstablishTime.setText(founddate);
        String term = this.term;
        isForever = term.contains("永久") || term.contains("长期") || term.contains("******");
        imgForever.setSelected(isForever);

        String[] times = term.split("至");

        if (null != times) {
            if (times.length > 0)
                tvStartTime.setText(times[0]);
            if (times.length > 1) {
                tvEndTime.setText(isForever ? "" : times[1]);
            }

        }
        etJyfw.setText(scope);

        isLock = true;
        unlockEdit();
    }


    public void next(OnNextListener onNextListener) {
        this.onNextListener = onNextListener;
        if (TextUtils.isEmpty(path)) {
            ToastUtils.showShort("请上传营业执照");
            onNextListener.onNext(false);
            return;
        } else {
            String tyshxydm = etTyshxydm.getText().toString().trim().toUpperCase();//统一社会信用代码
            if (TextUtils.isEmpty(tyshxydm)) {
                ToastUtils.showShort("请输入统一社会信用代码");
                onNextListener.onNext(false);
                return;
            }

//            if (!new UnifiedCodeValidator().codeValidate(tyshxydm)) {
//                ToastUtils.showShort("统一社会信用代码格式有误");
//                onNextListener.onNext(false);
//                return;
//            }

            String zzjgdm = etZzjgdm.getText().toString().trim();//组织机构代码
            String swdjh = etSwdjh.getText().toString().trim();//税务登记号
            String name = etName.getText().toString().trim();//名称
            if (TextUtils.isEmpty(name)) {
                ToastUtils.showShort("请输入市场主体名称");
                onNextListener.onNext(false);
                return;
            }
            String jc = etJc.getText().toString().trim();//简称
            if (TextUtils.isEmpty(jc)) {
                ToastUtils.showShort("请输入市场主体简称");
                onNextListener.onNext(false);
                return;
            }
            if (TextUtils.isEmpty(entType) || entType.equals("-1")) {
                ToastUtils.showShort("请选择企业类型");
                onNextListener.onNext(false);
                return;
            }

            String entAddress = etEntAddress.getText().toString().trim();//经营场所（住所）
            if (TextUtils.isEmpty(entAddress)) {
                ToastUtils.showShort("请输入企业住所");
                onNextListener.onNext(false);
                return;
            }
            String capital = etCapital.getText().toString().trim();//注册资本（万元）
            if (TextUtils.isEmpty(capital)) {
                ToastUtils.showShort("请输入注册资本");
                onNextListener.onNext(false);
                return;
            }

            if (TextUtils.isEmpty(establishTime)) {
                ToastUtils.showShort("请选择成立时间");
                onNextListener.onNext(false);
                return;
            }


            String jyfw = etJyfw.getText().toString().trim();//经营范围
            if (TextUtils.isEmpty(jyfw)) {
                ToastUtils.showShort("请输入经营范围");
                onNextListener.onNext(false);
                return;
            }

            String start = tvStartTime.getText().toString().trim();//营业范围 开始
            if (TextUtils.isEmpty(start)) {
                ToastUtils.showShort("请选择营业期限开始时间");
                onNextListener.onNext(false);
                return;
            }

            if (!isForever) {
                String end = tvEndTime.getText().toString().trim();//营业范围 结束
                if (TextUtils.isEmpty(end)) {
                    ToastUtils.showShort("请选择营业期限结束时间");
                    onNextListener.onNext(false);
                    return;
                }

            }


//            {
//                "creditcode": "91310000MA1FPFRF44", //统一社会信用代码
//                    "organizecode": "MA1FPFRF-4", //组织机构代码
//                    "taxcode": "310000MA1FPFRF4", //税务登记证号
//                    "membersName": "极易净水科技(上海)有限公司", //名称
//                    "aliasName": "极易净水科技(上海)有限公司", //简称
//                    "enterpriseType": "1",
//                    "regAddress": "上海市黄浦区新码头街55号4幢3楼", //经营场所（住所）
//                    "regcapital": 150, //注册资本（万元）
//                    "founddate": "2019-08-27", //成立日期
//                    "scope": "水处理设备、环保产品及零部件,空气调节设备及其零部件、家用电器、燃气器具、电热水器具、太阳能设备、医疗器械的研究、批发、进出口、佣金代理(拍卖除外)并提供相关配套服务。【依法须经批准的项目,经相关部门批准后方可开展经营活动】", //经营范围
//                    "companyId": "123456",
//                    "membersId": "123456", //售电公司ID
//                    "legalReprName": "朱芮", //姓名
//                    "businesstermStart": "2019-08-28", //营业期限开始
//                    "businesstermEnd": "至2049-08-27", //营业期限结束
//                    "businessterm": "2019年08月28日至2049年08月27日", //营业期限（选填）
//                    "isForever": false,
//                    "step": "1",
//                    "term": "2019-08-28至Invalid date" //营业期限（选填）
//            }

            String time;
            if (isForever) {
                time = tvStartTime.getText().toString() + "至永久";
            } else {
                time = tvStartTime.getText().toString() + "至" + tvEndTime.getText().toString();
            }

            List<DataDifferentItemBean> dataDifferentItemBeanList = new ArrayList<>();
            //判断输入的和识别的是否一致
            if (!isQueryBusinessInfoBack) {
                if (!TextUtils.isEmpty(creditcode))
                    if (!creditcode.equals(tyshxydm)) {
                        dataDifferentItemBeanList.add(new
                                DataDifferentItemBean("统一社会信用代码", tyshxydm, creditcode));
                    }

                if (!TextUtils.isEmpty(creditcode) && creditcode.length() == 18) {
                    StringBuilder stringBuilder = new StringBuilder(creditcode.substring(8, 17));
                    stringBuilder.insert(8, "-");
                    String s = stringBuilder.toString();
                    String substring = creditcode.substring(2, 17);
                    if (!s.equals(zzjgdm)) {
                        dataDifferentItemBeanList.add(new
                                DataDifferentItemBean("组织机构代码", zzjgdm, s));
                    }
                    if (!substring.equals(swdjh)) {
                        dataDifferentItemBeanList.add(new
                                DataDifferentItemBean("税务登记号", swdjh, substring));
                    }
                }
                if (!TextUtils.isEmpty(membersName))
                    if (!membersName.equals(name)) {
                        dataDifferentItemBeanList.add(new
                                DataDifferentItemBean("名称", name, membersName));
                    }
                if (!entType.equals("-1")) {
                    String ent = entTypes[Integer.parseInt(entType) - 1];
                    if (!TextUtils.isEmpty(enterpriseType))
                        if (!enterpriseType.equals(ent)) {
                            dataDifferentItemBeanList.add(new
                                    DataDifferentItemBean("企业类型", ent, enterpriseType));
                        }
                }
                if (!TextUtils.isEmpty(regAddress))
                    if (!regAddress.equals(entAddress)) {
                        dataDifferentItemBeanList.add(new
                                DataDifferentItemBean("经营场所（住所）", entAddress, regAddress));
                    }
                if (!TextUtils.isEmpty(regcapital))
                    if (!regcapital.equals(capital)) {
                        dataDifferentItemBeanList.add(new
                                DataDifferentItemBean("注册资本（万元）", capital, regcapital));
                    }
                if (!TextUtils.isEmpty(founddate))
                    if (!founddate.equals(establishTime)) {
                        dataDifferentItemBeanList.add(new
                                DataDifferentItemBean("成立时间", establishTime, founddate));
                    }
                if (!TextUtils.isEmpty(term))
                    if (!term.equals(time)) {
                        dataDifferentItemBeanList.add(new
                                DataDifferentItemBean("营业期限", time, term));
                    }
                if (!TextUtils.isEmpty(scope))
                    if (!scope.equals(jyfw)) {
                        dataDifferentItemBeanList.add(new
                                DataDifferentItemBean("经营范围", jyfw, scope));
                    }
            }
            if (dataDifferentItemBeanList.size() > 0) {
                new XPopup.Builder(getContext())
                        .isDestroyOnDismiss(true)
                        .isViewMode(true)
                        .asCustom(new DataDifferentDialog(getContext(),
                                "以下信息与系统识别信息不一致，请确认是否无误", dataDifferentItemBeanList
                                , new DataDifferentDialog.OnConfirmClickListener() {
                            @Override
                            public void onConfirm() {
                                save(tyshxydm, zzjgdm, swdjh, name, jc, entAddress, capital, jyfw, time);
                            }
                        }))
                        .show();
            } else {
                save(tyshxydm, zzjgdm, swdjh, name, jc, entAddress, capital, jyfw, time);
            }
        }
    }


    private void save(String tyshxydm, String zzjgdm, String swdjh, String name, String jc,
                      String entAddress, String capital, String jyfw, String term) {

        Map<String, Object> params = new HashMap<>();
        params.put("creditcode", tyshxydm);
        params.put("organizecode", zzjgdm);
        params.put("taxcode", swdjh);
        params.put("membersName", name);
        params.put("aliasName", jc);
        params.put("enterpriseType", entType);//
        params.put("regAddress", entAddress);
        params.put("regcapital", capital);
        params.put("founddate", establishTime);
        params.put("scope", jyfw);
        if (!TextUtils.isEmpty(legalReprName))
            params.put("legalReprName", legalReprName);
        params.put("isForever", isForever);
        params.put("step", "1");
        params.put("term", term);
        mPresenter.saveData(params);

    }


    public void showLayout() {
        llInfoLayout.setVisibility(View.VISIBLE);
        tvUnlockEdit.setVisibility(View.VISIBLE);
        llImgBtnLayout.setVisibility(View.VISIBLE);
    }

    /**
     * @param type 1 成立时间  2 营业期限开始时间  3 营业期限结束时间
     */
    private void showDateSelect(int type) {
        Calendar startDate = Calendar.getInstance();
        startDate.set(1800, 0, 1);
        Calendar endDate = Calendar.getInstance();
        endDate.set(2100, 0, 1);
        Calendar selectedDate = Calendar.getInstance();
        selectedDate.setTime(DateUtils.getMonthBackDate(-1));
        DialogUtil.showDateSelectDialog(mContext,
                new boolean[]{true, true, true, false, false, false}
                , startDate, endDate, selectedDate, new OnTimeSelectListener() {
                    @Override
                    public void onTimeSelect(Date date, View v) {
                        String string = TimeUtils.date2String(date, "yyyy-MM-dd");
                        if (type == 1) {
                            establishTime = string;
                            tvEstablishTime.setText(string);
                        } else if (type == 2) {
                            tvStartTime.setText(string);
                        } else if (type == 3) {
                            tvEndTime.setText(string);
                        }
                    }
                });
    }


}